<?php

namespace App\Http\Requests\Customers\Address;

use App\Http\Requests\ApiRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property string type
 * @property string $up_id
 */
class AddressCreateRequest extends ApiRequest
{
    const TYPE_COUNTRY = 'country';
    const TYPE_ZONE = 'zone';
    const TYPE_CITY = 'city';
    const TYPE_COUNTY = 'county';

    const VALID_TYPES = [
        self::TYPE_COUNTRY, self::TYPE_ZONE,
        self::TYPE_CITY, self::TYPE_COUNTY,
    ];

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'type'       => ['nullable','string', Rule::in(self::VALID_TYPES)],
            'up_id'      => 'int|min:1|required_unless:type,' . self::TYPE_COUNTRY,
        ];
    }
}
